from django.db import models
from django.contrib.auth.models import User


class Address(models.Model):
    """
    地址信息
    """
    # 是否为默认地址
    options = (
        (0, '不是默认地址'),
        (1, '默认地址')
    )

    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(User, on_delete=models.DO_NOTHING, verbose_name='用户ID')
    district = models.CharField(max_length=255, verbose_name='地区', null=True, blank='True')
    detail = models.CharField(max_length=255, verbose_name='详细地址', null=True, blank=True)
    postal_code = models.CharField(max_length=255, verbose_name='邮编')
    is_default = models.IntegerField(choices=options, verbose_name='是否为默认地址', default=0)
    receive_phone = models.CharField(max_length=11, verbose_name='收件人电话', null=True, blank=True)
    receive_name = models.CharField(max_length=255, verbose_name='收件人姓名', null=True, blank=True)

    def __str__(self):
        return str(self.detail)

    class Meta:
        verbose_name_plural = '地址管理'
        db_table = 'tb_address'

